package com.webdemo05.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;

import com.webdemo05.pojo.User;
import com.webdemo05.util.HibernateHandler;

public class QueryUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}
	@SuppressWarnings("unchecked")
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Session session  = HibernateHandler.newInstance().getCurrentSession();
		String hql = "from User";
		session.beginTransaction();
		List<User> users = session.createQuery(hql).list();
		session.getTransaction().commit();
		request.setAttribute("users", users);
		request.getRequestDispatcher("/WEB-INF/jsp/show.jsp").forward(request, response);
	}
}
